package com.example.musicplayer.dialogTools;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;

import com.example.musicplayer.R;

public class CreateMusicMenuDialog extends BaseDialog {
    private View mConfirm;
    private EditText mEditText;

    public CreateMusicMenuDialog(Context context) {
        super(context, R.style.AddMusicMenuDialog, R.style.AddMusicMenuDialog_NoAnim);
        mDialog.setCanceledOnTouchOutside(false);
    }

    @Override
    protected View setDialogView(Context context) {
        View view = View.inflate(context, R.layout.dialog_add_music_menu, null);
        mConfirm = view.findViewById(R.id.dialog_confirm);
        mEditText = view.findViewById(R.id.dialog_edittext);
        view.findViewById(R.id.dialog_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        return view;
    }

    @Override
    protected void setDialogLayout(Context context) {
        Window dialogWindow = mDialog.getWindow();
        if (dialogWindow != null) {
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            lp.width = (int) context.getResources().getDimension(R.dimen.dialog_add_music_menu_width);
            lp.height = (int) context.getResources().getDimension(R.dimen.dialog_add_music_menu_height);
            lp.gravity = Gravity.CENTER;
            dialogWindow.setAttributes(lp);
        }
    }

    public View getConfirm() {
        return mConfirm;
    }

    public String getInput() {
        return mEditText.getText().toString();
    }

    @Override
    public void show() {
        //设置自动弹出键盘
        mEditText.requestFocus();
        super.show();
    }
}